package jdklearning.nio.zerocopy;

import java.io.RandomAccessFile;

import java.nio.channels.FileChannel;

/**
 * @author shenenlu 2021年06月15日 下午13:51:01
 */
public class SendFileCopy {

    public static final String source = "/data/src.log";
    public static final String dest = "/data/dest.log";

    public static void main(String[] args) {
        try {
            FileChannel sourceChannel = new RandomAccessFile(source, "rw").getChannel();
            FileChannel destChannel = new RandomAccessFile(dest, "rw").getChannel();
            long start = System.currentTimeMillis();

            sourceChannel.transferTo(0, sourceChannel.size(), destChannel);
            System.out.println("耗时：" + (System.currentTimeMillis() - start));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
